<template>
    <div class="addressInfo">
        <div v-if="info.username">
            <van-contact-card
                type="edit"
                :name="info.username"
                :tel="info.userphone"
                @click="onEdit"
            />
        </div>
        <van-contact-card v-else type="add" @click="onAdd" />
    </div>
</template>

<script>
import { reqAddressList } from "../../../http/api"
export default {
    data() {
        return {
            info: {},
        }
    },
    mounted() {
        if (this.$route.query.addressId) {
            reqAddressList({
                id: this.$route.query.addressId,
                uid: JSON.parse(localStorage.getItem("isLogin")).uid,
            }).then((res) => {
                if (res.data.code == 200) {
                    this.info = res.data.list[0]
                }
            })
        }else{
            reqAddressList({
                uid:JSON.parse(localStorage.getItem("isLogin")).uid,
                status:1,
            }).then((res)=>{
                if(res.data.code==200){
                    if(res.data.list.length>0&&res.data.list.every(item=>item.status==1)){
                        this.info = res.data.list[0]
                    }
                }
            })
        }
    },
    methods: {
        //添加联系人跳转
        onAdd() {
            this.$router.replace("/a-list")
        },
        onEdit(){
            this.$router.replace("a-list")
        }
    }
}
</script>

<style>
</style>